package com.zm.demo.core.base;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @desc:
 * @author: z01140
 * @date: 2021/7/23 10:32
 */
public class DateTest {

    @Test
    public void getCurrentDate(){
        Date current = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(current);
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        System.out.println(c.getTimeInMillis());
        c.set(Calendar.MILLISECOND, 0);
        System.out.println(c.getTimeInMillis());
    }

    @Test
    public void dateAddTest() throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date current = sdf.parse("20210131");
        Calendar c = Calendar.getInstance();
        c.setTime(current);
        c.add(Calendar.MONTH, 1);
        System.out.println(c.getTime());

        current = sdf.parse("20210228");
        c = Calendar.getInstance();
        c.setTime(current);
        c.add(Calendar.MONTH, 1);
        System.out.println(c.getTime());
    }
}
